ALTER PROCEDURE [dbo].[CPP_User_EnterGradeScene]
  @dwUserID INT,
  @dwKindID INT,
  @szResult NVARCHAR(255) OUTPUT  -- 输出信息
AS
BEGIN

  -- 玩家判断
  DECLARE @Channel INT = 0
  DECLARE @IsAndroid INT = 0
  SELECT @Channel = Channel, @IsAndroid = IsAndroid FROM RYAccountsDB.dbo.AccountsInfo WHERE AccountsType = 0 AND UserID = @dwUserID
  IF @@ROWCOUNT<>1 BEGIN
    SET @szResult = N'玩家[' + CAST(@dwUserID AS NVARCHAR) + ']不存在'
    RETURN 1
  END
  
  -- 小游戏判断
  DECLARE @KindName NVARCHAR(255) = 'XX游戏'
  SELECT @KindName = KindName FROM RYPlatformDB.dbo.GameKindItem WHERE Nullity = 0 AND KindID = @dwKindID
  IF @@ROWCOUNT<>1 BEGIN
    SET @szResult = N'游戏[' + CAST(@dwKindID AS NVARCHAR) + ']未定义'
    RETURN 2
  END
  
  DECLARE @IsShare INT = 0
  DECLARE @DateID INT = CAST(CAST(GETDATE() AS FLOAT) AS INT)
  SELECT @IsShare = ID FROM [RYTreasureDB].[dbo].[RecordSharePresent] WHERE [DateID] = @DateID AND [UserID] = @dwUserID AND [KindID] = @dwKindID
  IF @IsShare>0 BEGIN
    SET @IsShare = 1
  END ELSE BEGIN
    SET @IsShare = 0
  END
  
  DECLARE @IsBind INT = 0
  DECLARE @RoomCard INT = 0
  DECLARE @AUserID INT = 0
  DECLARE @AGameID INT = 0
  
  DECLARE @ZengRoomCard INT = 1000
  
  SELECT @RoomCard = RoomCard, @AUserID = SpreaderID FROM [RYTreasureDB].[dbo].[UserRoomCard] WHERE UserID = @dwUserID AND KindID = @dwKindID
  IF @@ROWCOUNT=0 BEGIN
    IF @IsAndroid=1 BEGIN -- 判断是否为游客
      INSERT INTO [RYTreasureDB].[dbo].[UserRoomCard] (
        [UserID], [KindID], [RoomCard]
      ) VALUES (
        @dwUserID, @dwKindID, @ZengRoomCard
      )
    END
  END ELSE BEGIN
    IF @AUserID>0 BEGIN
      SET @IsBind = 1
      SELECT @AGameID = GameID FROM [RYAccountsDB].[dbo].[AccountsInfo] WHERE [AccountsType] = 1 AND [UserID] = @AUserID
    END
    IF @IsAndroid=1 AND @RoomCard<=0 BEGIN -- 判断是否为游客
      SET @RoomCard = @RoomCard + @ZengRoomCard
      UPDATE [RYTreasureDB].[dbo].[UserRoomCard] SET RoomCard = @RoomCard WHERE UserID = @dwUserID AND KindID = @dwKindID
    END
  END
  
  -- 是否分享（1） 是否绑定邀请码 （1）  邀请码的号  身上房卡数 
  SELECT
    @Channel AS Channel, @dwUserID AS UserID, @dwKindID AS KindID, @IsShare AS IsShare,
    @IsBind AS IsBind, @AUserID AS AUserID, @AGameID AS AGameID, @RoomCard AS RoomCard
  
  SET @szResult = 'SUCCESS'
  RETURN 0
END